home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / SWAG9605.DDD / 0049_Windows Sockets Unit.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-05-31  |  33.0 KB  |  1,030 lines

  1. unit WinSock;
  2.  
  3. {$C FIXED PRELOAD DISCARDABLE}
  4.  
  5. (*
  6.  * WINSOCK.H--definitions to be used with the WINSOCK.DLL
  7.  *
  8.  * This header file corresponds to version 1.1 of the Windows Sockets specification.
  9.  *
  10.  * This file includes parts which are Copyright (c) 1982-1986 Regents
  11.  * of the University of California.  All rights reserved.  The
  12.  * Berkeley Software License Agreement specifies the terms and
  13.  * conditions for redistribution.
  14.  *
  15.  * Original WINSOCK.H Change log:
  16.  *
  17.  * Fri Apr 23 16:31:01 1993  Mark Towfiq  (towfiq@Microdyne.COM)
  18.  *    New version from David Treadwell which adds extern "C" around
  19.  *    __WSAFDIsSet() and removes "const" from buf param of
  20.  *    WSAAsyncGetHostByAddr().  Added change log.
  21.  *
  22.  * Sat May 15 10:55:00 1993 David Treadwell (davidtr@microsoft.com)
  23.  *    Fix the IN_CLASSC macro to account for class-D multicasts.
  24.  *    Add AF_IPX == AF_NS.
  25.  *
  26.  * Tue Oct 19 13:05:02 1993  Mark Towfiq (Mark.Towfiq@Sun.COM)
  27.  *    New version from David Treadwell which changes type of counter in
  28.  *    fd_set to u_int instead of u_short, so that it is correctly
  29.  *    promoted in Winsdows NT and other 32-bit environments.
  30.  *
  31.  * Translated to BP7 by:  Randy Bratton, CServe: 72355,1466
  32.  *
  33.  * NOTE:  I have tried to keep the declaration order in WINSOCK.PAS the
  34.  *        same as that in WINSOCK.H.  Most of the comments from the original
  35.  *        WINSOCK.H have been left intact in the Pascal version.
  36.  *        My comments are labeled with RMB.
  37.  *
  38.  * NO WARRANTY EXPRESSED OR IMPLIED.
  39.  *
  40.  * WINSOCK.PAS Revision History
  41.  *    Version         Date      By     Comments
  42.  *      1.00        03/04/94    RMB    Initial revision.
  43.  *      1.01        08/22/94    RMB    General cleanup before posting to
  44.  *                                     CompuServe.
  45.  *      1.02        09/29/94    RMB    Added h_addr function for THostEnt
  46.  *                                     structure.
  47.  *      1.03        03/10/96    RMB    Fixed bug (noted by P. Payzant) in
  48.  *                                     TWSAData. Now corresponds to WINSOCK.H
  49.  *                                     dated 10/19/93 (except where noted).
  50.  *)
  51.  
  52. interface
  53.  
  54. uses
  55.   WinTypes;
  56.  
  57. type
  58. (*
  59.  * Basic system type definitions, taken from the BSD file sys/types.h.
  60.  *)
  61.   u_char  = char;
  62.   u_short = word;  (* in Borland C++, int and short are both 16-bits RMB *)
  63.   u_int   = word;
  64.   u_long  = longint;
  65.  
  66. (*
  67.  * Other basic types needed for the C to Pascal translation.  RMB
  68.  *)
  69.   PPChar = ^PChar;  (* used with char FAR * FAR * xxx   RMB *)
  70.  
  71. (*
  72.  * The new type to be used in all
  73.  * instances which refer to sockets.
  74.  *
  75.  * Must be renamed from SOCKET as there is a function called
  76.  * socket().  RMB
  77.  *)
  78.   PSocket = ^TSocket;
  79.   TSocket = u_int;
  80.  
  81. (*
  82.  * Select uses arrays of SOCKETs.  These macros manipulate such
  83.  * arrays.  FD_SETSIZE may be defined by the user before including
  84.  * this file, but the default here should be >= 64.
  85.  *
  86.  * CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
  87.  * INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE.
  88.  *)
  89. const
  90.   FD_SETSIZE =64;
  91.  
  92. type
  93.   PFd_Set = ^TFd_Set;
  94.   TFd_Set = record
  95.     fd_count : u_int;                              (* how many are SET? *) (* RMB 03/10/96 1.03 *)
  96.                                                    (* 10/19/93 update to original WINSOCK.H *)
  97.     fd_array : array[0..FD_SETSIZE-1] of TSocket;  (* an array of SOCKETs *)
  98.     end;
  99.  
  100. function  __WSAFDIsSet(fd: TSocket; aset: PFd_Set): integer;
  101.  
  102. (*
  103. **  NB:  Have not done any work with socket arrays, therefore these
  104. **  routines have not been tested.  RMB 08/22/94 1.01
  105. *)
  106. procedure Fd_Clr(fd: TSocket; aset: PFd_Set);
  107. procedure Fd_Set(fd: TSocket; aset: PFd_Set);
  108. procedure Fd_Zero(aset: PFd_Set);
  109. function  Fd_IsSet(fd: TSocket; aset: PFd_Set): boolean;
  110.  
  111. (*
  112.  * Structure used in select() call, taken from the BSD file sys/time.h.
  113.  *)
  114. type
  115.   PTimeval = ^Timeval;
  116.   Timeval = record
  117.         tv_sec: longint;         (* seconds *)
  118.         tv_usec: longint;        (* and microseconds *)
  119.         end;
  120. (*
  121.  * Operations on timevals.
  122.  *
  123.  * NB: timercmp does not work for >= or <=.
  124.  *)
  125. (*
  126. **  DEFINES (macros) for timerisset, timercmp, and timerclear
  127. **  not implemented.  RMB
  128. *)
  129.  
  130. (*
  131.  * Commands for ioctlsocket(),  taken from the BSD file fcntl.h.
  132.  *
  133.  *
  134.  * Ioctl's have the command encoded in the lower word,
  135.  * and the size of any in or out parameters in the upper
  136.  * word.  The high 2 bits of the upper word are used
  137.  * to encode the in/out status of the parameter; for now
  138.  * we restrict parameters to at most 128 bytes.
  139.  *)
  140. const
  141.   IOCPARM_MASK =   $07f;            (* parameters must be < 128 bytes *)
  142.   IOC_VOID     =   $20000000;       (* no parameters *)
  143.   IOC_OUT      =   $040000000;      (* copy out parameters *)
  144.   IOC_IN       =   $080000000;      (* copy in parameters *)
  145.   IOC_INOUT    =   (IOC_IN or IOC_OUT);
  146.                                                                                 (* 0x20000000 distinguishes new &
  147.                                                                                      old ioctl's *)
  148. (*
  149. **  DEFINES (macros) for _IO, _IOR, _IOW, FIONREAD, FIONBIO, FIOASYNC,
  150. **    SIOCSHIWAT, SIOCGHIWAT, SIOCSLOWAT, SIOCGLOWAT, SIOCATMARK
  151. **    not implemented.  RMB
  152. *)
  153.  
  154. (*
  155.  * Structures returned by network data base library, taken from the
  156.  * BSD file netdb.h.  All addresses are supplied in host order, and
  157.  * returned in network order (suitable for use in system calls).
  158.  *)
  159.  
  160. type
  161.   PHostEnt = ^THostEnt;
  162.   THostEnt = record
  163.         h_name : PChar;           (* official name of host *)
  164.         h_aliases: PPChar;        (* alias list *)
  165.         h_addrtype: integer;      (* host address type *)
  166.         h_length :  integer;      (* length of address *)
  167.         h_addr_list: PPChar;      (* list of addresses *)
  168.         end;
  169.  
  170. {
  171.   C #define h_addr h_addr_list[0] omitted as currently only needed for
  172.   backward compatibility.  RMB 08/22/94 1.01
  173. }
  174. function h_addr(aHostEnt: THostEnt): PChar;  (* RMB 09/29/94 1.02 *)
  175.  
  176. (*
  177.  * It is assumed here that a network number
  178.  * fits in 32 bits.
  179.  *)
  180. type
  181.   PNetEnt = ^TNetEnt;
  182.   TNetEnt = record
  183.         n_name : PChar;           (* official name of net *)
  184.         n_aliases : PPChar;       (* alias list *)
  185.         n_addrtype : integer;     (* net address type *)
  186.         n_net : u_long;           (* network $ *)
  187.         end;
  188.  
  189. type
  190.   PServEnt = ^TServEnt;
  191.   TServEnt = record
  192.         s_name : PChar;           (* official service name *)
  193.         s_aliases : PPChar;       (* alias list *)
  194.         s_port : integer;         (* port $ *)
  195.         s_proto : PChar;          (* protocol to use *)
  196.         end;
  197.  
  198. type
  199.   PProtoEnt = ^TProtoEnt;
  200.   TProtoEnt = record
  201.         p_name : PChar;           (* official protocol name *)
  202.         p_aliases : PPChar;       (* alias list *)
  203.         p_proto : integer;        (* protocol $ *)
  204.         end;
  205.  
  206. (*
  207.  * Constants and procedures defined by the internet system,
  208.  * Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
  209.  *)
  210.  
  211. (*
  212.  * Protocols
  213.  *)
  214. const
  215.    IPPROTO_IP          =    0;               (* dummy for IP *)
  216.    IPPROTO_ICMP        =    1;               (* control message protocol *)
  217.    IPPROTO_GGP         =    2;               (* gateway^2 (deprecated) *)
  218.    IPPROTO_TCP         =    6;               (* tcp *)
  219.    IPPROTO_PUP         =    12;              (* pup *)
  220.    IPPROTO_UDP         =    17;              (* user datagram protocol *)
  221.    IPPROTO_IDP         =    22;              (* xns idp *)
  222.    IPPROTO_ND          =    77;              (* UNOFFICIAL net disk proto *)
  223.  
  224.    IPPROTO_RAW         =    255;             (* raw IP packet *)
  225.    IPPROTO_MAX         =    256;
  226.  
  227. (*
  228.  * Port/socket numbers: network standard functions
  229.  *)
  230.    IPPORT_ECHO         =    7;
  231.    IPPORT_DISCARD      =    9;
  232.    IPPORT_SYSTAT       =    11;
  233.    IPPORT_DAYTIME      =    13;
  234.    IPPORT_NETSTAT      =    15;
  235.    IPPORT_FTP          =    21;
  236.    IPPORT_TELNET       =    23;
  237.    IPPORT_SMTP         =    25;
  238.    IPPORT_TIMESERVER   =    37;
  239.    IPPORT_NAMESERVER   =    42;
  240.    IPPORT_WHOIS        =    43;
  241.    IPPORT_MTP          =    57;
  242.  
  243. (*
  244.  * Port/socket numbers: host specific functions
  245.  *)
  246.    IPPORT_TFTP         =    69;
  247.    IPPORT_RJE          =    77;
  248.    IPPORT_FINGER       =    79;
  249.    IPPORT_TTYLINK      =    87;
  250.    IPPORT_SUPDUP       =    95;
  251.  
  252. (*
  253.  * UNIX TCP sockets
  254.  *)
  255.    IPPORT_EXECSERVER   =    512;
  256.    IPPORT_LOGINSERVER  =    513;
  257.    IPPORT_CMDSERVER    =    514;
  258.    IPPORT_EFSSERVER    =    520;
  259.  
  260. (*
  261.  * UNIX UDP sockets
  262.  *)
  263.    IPPORT_BIFFUDP      =    512;
  264.    IPPORT_WHOSERVER    =    513;
  265.    IPPORT_ROUTESERVER  =    520;
  266.                                                                                 (* 520+1 also used *)
  267.  
  268. (*
  269.  * Ports < IPPORT_RESERVED are reserved for
  270.  * privileged processes (e.g. root).
  271.  *)
  272.    IPPORT_RESERVED    =     1024;
  273.  
  274. (*
  275.  * Link numbers
  276.  *)
  277.    IMPLINK_IP         =     155;
  278.    IMPLINK_LOWEXPER   =     156;
  279.    IMPLINK_HIGHEXPER  =     158;
  280.  
  281. (*
  282.  * Internet address (old style... should be updated)
  283.  *)
  284. type
  285.   PIn_Addr = ^TIn_Addr;
  286.   TIn_Addr = record
  287.         case integer of
  288.           1: (S_un_b : record
  289.                       s_b1,
  290.                       s_b2,
  291.                       s_b3,
  292.                       s_b4 : u_char;
  293.                       end);
  294.           2: (S_un_w : record
  295.                       s_w1,
  296.                       s_w2 : u_short;
  297.                       end);
  298.           3: (S_addr : u_long);
  299.         end;
  300.  
  301. function s_addr(s_un: TIn_Addr): u_long;
  302. function s_host(s_un: TIn_Addr): u_char;
  303. function s_net(s_un: TIn_Addr): u_char;
  304. function s_imp(s_un: TIn_Addr): u_short;
  305. function s_impno(s_un: TIn_Addr): u_char;
  306. function s_lh(s_un: TIn_Addr): u_char;
  307.  
  308. (*
  309.  * Definitions of bits in internet address integers.
  310.  * On subnets, the decomposition of addresses to host and net parts
  311.  * is done according to subnet mask, not the masks here.
  312.  *)
  313. const
  314.   IN_CLASSA_NET       =    $ff000000;
  315.   IN_CLASSA_NSHIFT    =    24;
  316.   IN_CLASSA_HOST      =    $00ffffff;
  317.   IN_CLASSA_MAX       =    128;
  318.  
  319.   IN_CLASSB_NET       =    $ffff0000;
  320.   IN_CLASSB_NSHIFT    =    16;
  321.   IN_CLASSB_HOST      =    $0000ffff;
  322.   IN_CLASSB_MAX       =    65536;
  323.  
  324.   IN_CLASSC_NET       =    $ffffff00;
  325.   IN_CLASSC_NSHIFT    =    8;
  326.   IN_CLASSC_HOST      =    $000000ff;
  327.  
  328.   INADDR_ANY          =    $000000000;
  329.   INADDR_LOOPBACK     =    $7f000001;
  330.   INADDR_BROADCAST    =    $ffffffff;
  331.   INADDR_NONE         =    $ffffffff;
  332.  
  333. function In_ClassA(i : longint) : boolean;
  334. function In_ClassB(i : longint) : boolean;
  335. function In_ClassC(i : longint) : boolean;
  336.  
  337. (*
  338.  * Socket address, internet style.
  339.  *)
  340. type
  341.   PSockAddr_In = ^TSockAddr_In;
  342.   TSockAddr_in = record
  343.           sin_family  : integer;
  344.           sin_port    : u_short;
  345.           sin_addr    : TIn_Addr;
  346.           sin_zero    : array[0..7] of char;
  347.           end;
  348.  
  349. const
  350.   WSADESCRIPTION_LEN   =   256;
  351.   WSASYS_STATUS_LEN    =   128;
  352.  
  353. type
  354.   PWSAData = ^TWSAData;
  355.   TWSAData = record
  356.           wVersion       : word;
  357.           wHighVersion   : word;
  358.           szDescription  : array[0..WSADESCRIPTION_LEN] of char;  (* RMB 03/10/96 1.03 *)
  359.           szSystemStatus : array[0..WSASYS_STATUS_LEN] of char;   (* RMB 03/10/96 1.03 *)
  360.           iMaxSockets    : u_short;
  361.           iMaxUdpDg      : u_short;
  362.           lpVendorInfo   : PChar;
  363.           end;
  364.  
  365. (*
  366.  * Options for use with [gs]etsockopt at the IP level.
  367.  *)
  368. const
  369.  
  370.   IP_OPTIONS  =    1;               (* set/get IP per-packet options *)
  371.  
  372. (*
  373.  * Definitions related to sockets: types, address families, options,
  374.  * taken from the BSD file sys/socket.h.
  375.  *)
  376.  
  377. (*
  378.  * This is used instead of -1, since the
  379.  * SOCKET type is unsigned.
  380.  *)
  381. const
  382.   INVALID_SOCKET = TSocket(not 0);
  383.   SOCKET_ERROR   = -1;
  384.  
  385. (*
  386.  * Types
  387.  *)
  388.   SOCK_STREAM     = 1;               (* stream socket *)
  389.   SOCK_DGRAM      = 2;               (* datagram socket *)
  390.   SOCK_RAW        = 3;               (* raw-protocol interface *)
  391.   SOCK_RDM        = 4;               (* reliably-delivered message *)
  392.   SOCK_SEQPACKET  = 5;               (* sequenced packet stream *)
  393.  
  394. (*
  395.  * Option flags per-socket.
  396.  *)
  397.   SO_DEBUG        = $0001;          (* turn on debugging info recording *)
  398.   SO_ACCEPTCONN   = $0002;          (* socket has had listen() *)
  399.   SO_REUSEADDR    = $0004;          (* allow local address reuse *)
  400.   SO_KEEPALIVE    = $0008;          (* keep connections alive *)
  401.   SO_DONTROUTE    = $0010;          (* just use interface addresses *)
  402.   SO_BROADCAST    = $0020;          (* permit sending of broadcast msgs *)
  403.   SO_USELOOPBACK  = $0040;          (* bypass hardware when possible *)
  404.   SO_LINGER       = $0080;          (* linger on close if data present *)
  405.   SO_OOBINLINE    = $0100;          (* leave received OOB data in line *)
  406.  
  407.   SO_DONTLINGER   = u_int(not SO_LINGER);
  408.  
  409. (*
  410.  * Additional options.
  411.  *)
  412.   SO_SNDBUF       = $1001;          (* send buffer size *)
  413.   SO_RCVBUF       = $1002;          (* receive buffer size *)
  414.   SO_SNDLOWAT     = $1003;          (* send low-water mark *)
  415.   SO_RCVLOWAT     = $1004;          (* receive low-water mark *)
  416.   SO_SNDTIMEO     = $1005;          (* send timeout *)
  417.   SO_RCVTIMEO     = $1006;          (* receive timeout *)
  418.   SO_ERROR        = $1007;          (* get error status and clear *)
  419.   SO_TYPE         = $1008;          (* get socket type *)
  420.  
  421. (*
  422.  * TCP options.
  423.  *)
  424.   TCP_NODELAY     = $0001;
  425.  
  426. (*
  427.  * Address families.
  428.  *)
  429.   AF_UNSPEC       = 0;               (* unspecified *)
  430.   AF_UNIX         = 1;               (* local to host (pipes, portals) *)
  431.   AF_INET         = 2;               (* internetwork: UDP, TCP, etc. *)
  432.   AF_IMPLINK      = 3;               (* arpanet imp addresses *)
  433.   AF_PUP          = 4;               (* pup protocols: e.g. BSP *)
  434.   AF_CHAOS        = 5;               (* mit CHAOS protocols *)
  435.   AF_NS           = 6;               (* XEROX NS protocols *)
  436.   AF_IPX          = 6;               (* IPX and SPX *) (* RMB 03/10/96 1.03 *)
  437.                                                        (* 05/15/93 update to original WINSOCK.H *)
  438.   AF_ISO          = 7;               (* ISO protocols *)
  439.   AF_OSI          = AF_ISO;          (* OSI is ISO *)
  440.   AF_ECMA         = 8;               (* european computer manufacturers *)
  441.   AF_DATAKIT      = 9;               (* datakit protocols *)
  442.   AF_CCITT        = 10;              (* CCITT protocols, X.25 etc *)
  443.   AF_SNA          = 11;              (* IBM SNA *)
  444.   AF_DECnet       = 12;              (* DECnet *)
  445.   AF_DLI          = 13;              (* Direct data link interface *)
  446.   AF_LAT          = 14;              (* LAT *)
  447.   AF_HYLINK       = 15;              (* NSC Hyperchannel *)
  448.   AF_APPLETALK    = 16;              (* AppleTalk *)
  449.   AF_NETBIOS      = 17;              (* NetBios-style addresses *)
  450.  
  451.   AF_MAX          = 18;
  452.  
  453. (*
  454.  * Structure used by kernel to store most
  455.  * addresses.
  456.  *)
  457. type
  458.   PSockAddr = ^TSockAddr;
  459.   TSockAddr = record
  460.         sa_family : u_short;            (* address family *)
  461.         sa_data : array[0..13] of char; (* up to 14 bytes of direct address *)
  462.         end;
  463.  
  464. (*
  465.  * Structure used by kernel to pass protocol
  466.  * information in raw sockets.
  467.  *)
  468. type
  469.   PSockProto = ^TSockProto;
  470.   TSockProto = record
  471.         sp_family : u_short;              (* address family *)
  472.         sp_protocol : u_short;            (* protocol *)
  473.         end;
  474.  
  475. (*
  476.  * Protocol families, same as address families for now.
  477.  *)
  478. const
  479.  
  480.   PF_UNSPEC       = AF_UNSPEC;
  481.   PF_UNIX         = AF_UNIX;
  482.   PF_INET         = AF_INET;
  483.   PF_IMPLINK      = AF_IMPLINK;
  484.   PF_PUP          = AF_PUP;
  485.   PF_CHAOS        = AF_CHAOS;
  486.   PF_NS           = AF_NS;
  487.   PF_IPX          = AF_IPX;  (* RMB 3/9/96 1.03 *)
  488.                              (* 5/15/93 update to original WINSOCK.H *)
  489.   PF_ISO          = AF_ISO;
  490.   PF_OSI          = AF_OSI;
  491.   PF_ECMA         = AF_ECMA;
  492.   PF_DATAKIT      = AF_DATAKIT;
  493.   PF_CCITT        = AF_CCITT;
  494.   PF_SNA          = AF_SNA;
  495.   PF_DECnet       = AF_DECnet;
  496.   PF_DLI          = AF_DLI;
  497.   PF_LAT          = AF_LAT;
  498.   PF_HYLINK       = AF_HYLINK;
  499.   PF_APPLETALK    = AF_APPLETALK;
  500.  
  501.   PF_MAX          = AF_MAX;
  502.  
  503. (*
  504.  * Structure used for manipulating linger option.
  505.  *)
  506. type
  507.   PLinger = ^TLinger;
  508.   TLinger = record
  509.           l_onoff  : WordBool; {was u_short RMB} (* option on/off *) (* RMB 03/10/96 1.03 *)
  510.           l_linger : u_short;                    (* linger time *)
  511.           end;
  512.  
  513. (*
  514.  * Level number for (get/set)sockopt() to apply to socket itself.
  515.  *)
  516. const
  517.   SOL_SOCKET      = -1; {was $ffff  RMB}  (* options for socket level *)
  518.  
  519. (*
  520.  * Maximum queue length specifiable by listen.
  521.  *)
  522. const
  523.   SOMAXCONN       = 5;
  524.  
  525.   MSG_OOB         = $1;             (* process out-of-band data *)
  526.   MSG_PEEK        = $2;             (* peek at incoming message *)
  527.   MSG_DONTROUTE   = $4;             (* send without using routing tables *)
  528.  
  529.   MSG_MAXIOVLEN   = 16;
  530.  
  531. (*
  532.  * Define constant based on rfc883, used by gethostbyxxxx() calls.
  533.  *)
  534. const
  535.   MAXGETHOSTSTRUCT        = 1024;
  536.  
  537. (*
  538.  * Define flags to be used with the WSAAsyncSelect() call.
  539.  *)
  540. const
  541.   FD_READ         = $01;
  542.   FD_WRITE        = $02;
  543.   FD_OOB          = $04;
  544.   FD_ACCEPT       = $08;
  545.   FD_CONNECT      = $10;
  546.   FD_CLOSE        = $20;
  547.  
  548. (*
  549.  * All Windows Sockets error constants are biased by WSABASEERR from
  550.  * the "normal"
  551.  *)
  552. const
  553.   WSABASEERR              = 10000;
  554.  
  555. (*
  556.  * Windows Sockets definitions of regular Microsoft C error constants
  557.  *)
  558. const
  559.   WSAEINTR                = (WSABASEERR+4);
  560.   WSAEBADF                = (WSABASEERR+9);
  561.   WSAEACCES               = (WSABASEERR+13);
  562.   WSAEFAULT               = (WSABASEERR+14);
  563.   WSAEINVAL               = (WSABASEERR+22);
  564.   WSAEMFILE               = (WSABASEERR+24);
  565.  
  566. (*
  567.  * Windows Sockets definitions of regular Berkeley error constants
  568.  *)
  569. const
  570.   WSAEWOULDBLOCK          = (WSABASEERR+35);
  571.   WSAEINPROGRESS          = (WSABASEERR+36);
  572.   WSAEALREADY             = (WSABASEERR+37);
  573.   WSAENOTSOCK             = (WSABASEERR+38);
  574.   WSAEDESTADDRREQ         = (WSABASEERR+39);
  575.   WSAEMSGSIZE             = (WSABASEERR+40);
  576.   WSAEPROTOTYPE           = (WSABASEERR+41);
  577.   WSAENOPROTOOPT          = (WSABASEERR+42);
  578.   WSAEPROTONOSUPPORT      = (WSABASEERR+43);
  579.   WSAESOCKTNOSUPPORT      = (WSABASEERR+44);
  580.   WSAEOPNOTSUPP           = (WSABASEERR+45);
  581.   WSAEPFNOSUPPORT         = (WSABASEERR+46);
  582.   WSAEAFNOSUPPORT         = (WSABASEERR+47);
  583.   WSAEADDRINUSE           = (WSABASEERR+48);
  584.   WSAEADDRNOTAVAIL        = (WSABASEERR+49);
  585.   WSAENETDOWN             = (WSABASEERR+50);
  586.   WSAENETUNREACH          = (WSABASEERR+51);
  587.   WSAENETRESET            = (WSABASEERR+52);
  588.   WSAECONNABORTED         = (WSABASEERR+53);
  589.   WSAECONNRESET           = (WSABASEERR+54);
  590.   WSAENOBUFS              = (WSABASEERR+55);
  591.   WSAEISCONN              = (WSABASEERR+56);
  592.   WSAENOTCONN             = (WSABASEERR+57);
  593.   WSAESHUTDOWN            = (WSABASEERR+58);
  594.   WSAETOOMANYREFS         = (WSABASEERR+59);
  595.   WSAETIMEDOUT            = (WSABASEERR+60);
  596.   WSAECONNREFUSED         = (WSABASEERR+61);
  597.   WSAELOOP                = (WSABASEERR+62);
  598.   WSAENAMETOOLONG         = (WSABASEERR+63);
  599.   WSAEHOSTDOWN            = (WSABASEERR+64);
  600.   WSAEHOSTUNREACH         = (WSABASEERR+65);
  601.   WSAENOTEMPTY            = (WSABASEERR+66);
  602.   WSAEPROCLIM             = (WSABASEERR+67);
  603.   WSAEUSERS               = (WSABASEERR+68);
  604.   WSAEDQUOT               = (WSABASEERR+69);
  605.   WSAESTALE               = (WSABASEERR+70);
  606.   WSAEREMOTE              = (WSABASEERR+71);
  607.  
  608. (*
  609.  * Extended Windows Sockets error constant definitions
  610.  *)
  611. const
  612.   WSASYSNOTREADY          = (WSABASEERR+91);
  613.   WSAVERNOTSUPPORTED      = (WSABASEERR+92);
  614.   WSANOTINITIALISED       = (WSABASEERR+93);
  615.  
  616. (*
  617.  * Error return codes from gethostbyname() and gethostbyaddr()
  618.  * (when using the resolver). Note that these errors are
  619.  * retrieved via WSAGetLastError() and must therefore follow
  620.  * the rules for avoiding clashes with error numbers from
  621.  * specific implementations or language run-time systems.
  622.  * For this reason the codes are based at WSABASEERR+1001.
  623.  * Note also that [WSA]NO_ADDRESS is defined only for
  624.  * compatibility purposes.
  625.  *)
  626.  
  627. function h_errno : integer;
  628.  
  629. const
  630. (* Authoritative Answer: Host not found *)
  631.   WSAHOST_NOT_FOUND       = (WSABASEERR+1001);
  632.   HOST_NOT_FOUND          = WSAHOST_NOT_FOUND;
  633.  
  634. (* Non-Authoritative: Host not found, or SERVERFAIL *)
  635.   WSATRY_AGAIN            = (WSABASEERR+1002);
  636.   TRY_AGAIN               = WSATRY_AGAIN;
  637.  
  638. (* Non recoverable errors, FORMERR, REFUSED, NOTIMP *)
  639.   WSANO_RECOVERY          = (WSABASEERR+1003);
  640.   NO_RECOVERY             = WSANO_RECOVERY;
  641.  
  642. (* Valid name, no data record of requested type *)
  643.   WSANO_DATA              = (WSABASEERR+1004);
  644.   NO_DATA                 = WSANO_DATA;
  645.  
  646. (* no address, look for MX record *)
  647.   WSANO_ADDRESS           = WSANO_DATA;
  648.   NO_ADDRESS              = WSANO_ADDRESS;
  649.  
  650. (*
  651.  * Windows Sockets errors redefined as regular Berkeley error constants
  652.  *)
  653. const
  654.   EWOULDBLOCK             = WSAEWOULDBLOCK;
  655.   EINPROGRESS             = WSAEINPROGRESS;
  656.   EALREADY                = WSAEALREADY;
  657.   ENOTSOCK                = WSAENOTSOCK;
  658.   EDESTADDRREQ            = WSAEDESTADDRREQ;
  659.   EMSGSIZE                = WSAEMSGSIZE;
  660.   EPROTOTYPE              = WSAEPROTOTYPE;
  661.   ENOPROTOOPT             = WSAENOPROTOOPT;
  662.   EPROTONOSUPPORT         = WSAEPROTONOSUPPORT;
  663.   ESOCKTNOSUPPORT         = WSAESOCKTNOSUPPORT;
  664.   EOPNOTSUPP              = WSAEOPNOTSUPP;
  665.   EPFNOSUPPORT            = WSAEPFNOSUPPORT;
  666.   EAFNOSUPPORT            = WSAEAFNOSUPPORT;
  667.   EADDRINUSE              = WSAEADDRINUSE;
  668.   EADDRNOTAVAIL           = WSAEADDRNOTAVAIL;
  669.   ENETDOWN                = WSAENETDOWN;
  670.   ENETUNREACH             = WSAENETUNREACH;
  671.   ENETRESET               = WSAENETRESET;
  672.   ECONNABORTED            = WSAECONNABORTED;
  673.   ECONNRESET              = WSAECONNRESET;
  674.   ENOBUFS                 = WSAENOBUFS;
  675.   EISCONN                 = WSAEISCONN;
  676.   ENOTCONN                = WSAENOTCONN;
  677.   ESHUTDOWN               = WSAESHUTDOWN;
  678.   ETOOMANYREFS            = WSAETOOMANYREFS;
  679.   ETIMEDOUT               = WSAETIMEDOUT;
  680.   ECONNREFUSED            = WSAECONNREFUSED;
  681.   ELOOP                   = WSAELOOP;
  682.   ENAMETOOLONG            = WSAENAMETOOLONG;
  683.   EHOSTDOWN               = WSAEHOSTDOWN;
  684.   EHOSTUNREACH            = WSAEHOSTUNREACH;
  685.   ENOTEMPTY               = WSAENOTEMPTY;
  686.   EPROCLIM                = WSAEPROCLIM;
  687.   EUSERS                  = WSAEUSERS;
  688.   EDQUOT                  = WSAEDQUOT;
  689.   ESTALE                  = WSAESTALE;
  690.   EREMOTE                 = WSAEREMOTE;
  691.  
  692. (* Socket function prototypes *)
  693.  
  694. function accept(s: TSOCKET; addr: PSockAddr; addrlen: PInteger): TSOCKET;
  695.  
  696. function bind(s: TSOCKET; const addr: PSockAddr; namelen: integer): integer;
  697.  
  698. function closesocket(s: TSOCKET): integer;
  699.  
  700. function connect(s: TSOCKET; const name: PSockAddr; namelen: integer): integer;
  701.  
  702. function getpeername(s: TSOCKET; name: PSockAddr; namelen: PInteger): integer;
  703.  
  704. function getsockname(s: TSOCKET; name: PSockAddr; namelen: PInteger): integer;
  705.  
  706. function getsockopt(s: TSOCKET; level: integer; optname: integer;
  707.                     optval: PChar; optlen: PInteger): integer;
  708.  
  709. function htonl(hostlong: u_long): u_long;
  710.  
  711. function htons(hostshort: u_short): u_short;
  712.  
  713. function inet_addr(const cp: PChar): longint;
  714.  
  715. function inet_ntoa(ain: TIn_Addr): PChar;
  716.  
  717. function ioctlsocket(s: TSOCKET; cmd: longint; argp: PLongint) : integer;
  718.  
  719. function listen (s: TSOCKET; backlog: integer): integer;
  720.  
  721. function ntohl(netlong: u_long): u_long;
  722.  
  723. function ntohs(netshort: u_short): u_short;
  724.  
  725. function recv(s : TSOCKET; buf: PChar; len: integer; flags: integer): integer;
  726.  
  727. function recvfrom(s : TSOCKET; buf: PChar; len: integer; flags: integer;
  728.                   from: PSockAddr; fromlen: PInteger): integer;
  729.  
  730. function select(nfds: integer; readfds: PFd_Set; writefds: PFd_Set;
  731.                 exceptfds: PFd_Set; const timeout: PTimeval): integer;
  732.  
  733. function send(s: TSOCKET; const buf: PChar; len: integer; flags: integer): integer;
  734.  
  735. function sendto(s: TSOCKET; const buf: PChar; len: integer; flags: integer;
  736.                 const ato: PSockAddr; tolen: integer): integer;
  737.  
  738. function setsockopt(s: TSOCKET; level: integer; optname: integer;
  739.                     const optval: PChar; optlen: integer): integer;
  740.  
  741. function shutdown(s: TSOCKET; how: integer): integer;
  742.  
  743. function socket(af: integer; atype: integer; protocol: integer): TSOCKET;
  744.  
  745. (* Database function prototypes *)
  746.  
  747. function gethostbyaddr(const addr: PChar; len: integer; atype: integer): PHostEnt;
  748.  
  749. function gethostbyname(const name: PChar): PHostEnt;
  750.  
  751. function gethostname(name: PChar; namelen: integer): integer;
  752.  
  753. function getprotobyname(const name: PChar): PProtoEnt;
  754.  
  755. function getprotobynumber(proto: integer): PProtoEnt;
  756.  
  757. function getservbyname(const name: PChar; const proto: PChar): PServEnt;
  758.  
  759. function getservbyport(port: integer; const proto: PChar): PServEnt;
  760.  
  761.  
  762. (* Microsoft Windows Extension function prototypes *)
  763.  
  764. function WSAAsyncGetHostByAddr(hWnd: HWND; wMsg: u_int;
  765.                                const addr: PChar; len: integer; atype: integer;
  766.                                buf: PChar; buflen: integer): THandle;  (* RMB 03/10/96 1.03 *)
  767.                                                   (* 04/23/93 update to original WINSOCK.H *)
  768.  
  769. function WSAAsyncGetHostByName(hWnd: HWND; wMsg: u_int;
  770.                                const name: PChar; buf: PChar;
  771.                                buflen: integer): THandle;
  772.  
  773. function WSAAsyncGetProtoByName(hWnd: HWND; wMsg: u_int;
  774.                                 const name: PChar; buf: PChar;
  775.                                 buflen: integer): THandle;
  776.  
  777. function WSAAsyncGetProtoByNumber(hWnd: HWND; wMsg: u_int;
  778.                                   number: integer; buf: PChar;
  779.                                   buflen: integer): THandle;
  780.  
  781. function WSAAsyncGetServByName(hWnd: HWND; wMsg: u_int;
  782.                                const name: PChar;
  783.                                const proto: PChar;
  784.                                buf: PChar; buflen: integer): THandle;
  785.  
  786. function WSAAsyncGetServByPort(hWnd: HWND; wMsg: u_int; port: integer;
  787.                                const proto: PChar; buf: PChar;
  788.                                buflen: integer): THandle;
  789.  
  790. function WSAAsyncSelect(s : TSocket; hWnd: HWND; wMsg: u_int;
  791.                         lEvent: longint): integer;
  792.  
  793. function WSACancelAsyncRequest(hAsyncTaskHandle: THandle): integer;
  794.  
  795. function WSACancelBlockingCall: integer;
  796.  
  797. function WSACleanup: integer;
  798.  
  799. function WSAGetLastError: integer;
  800.  
  801. function WSAIsBlocking: boolean;
  802.  
  803. function WSASetBlockingHook(lpBlockFunc: TFarProc): TFarProc;
  804.  
  805. procedure WSASetLastError(iError: integer);
  806.  
  807. function WSAStartup(wVersionRequired: word; lpWSAData: PWSAData): integer;
  808.  
  809. function WSAUnhookBlockingHook: integer;
  810.  
  811. (*
  812.  * Windows message parameter composition and decomposition
  813.  * macros.
  814.  *
  815.  * WSAMAKEASYNCREPLY is inteneded for use by the Windows Sockets implementation
  816.  * when constructing the response to a WSAAsyncGetXByX() routine.
  817.  *)
  818. function WSAMakeAsyncReply(buflen, error: word): longint;
  819. (*
  820.  * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
  821.  * when constructing the response to WSAAsyncSelect().
  822.  *)
  823. function WSAMakeSelectReply(event, error: word): longint;
  824. (*
  825.  * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
  826.  * to extract the buffer length from the lParam in the response
  827.  * to a WSAGetXByY().
  828.  *)
  829. function WSAGetAsyncBuflen(lparam: longint): word;
  830. (*
  831.  * WSAGETASYNCERROR is intended for use by the Windows Sockets application
  832.  * to extract the error code from the lParam in the response
  833.  * to a WSAGetXByY().
  834.  *)
  835. function WSAGetAsyncError(lparam: longint): word;
  836. (*
  837.  * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
  838.  * to extract the event code from the lParam in the response
  839.  * to a WSAAsyncSelect().
  840.  *)
  841. function WSAGetSelectEvent(lparam: longint): word;
  842. (*
  843.  * WSAGETSELECTERROR is intended for use by the Windows Sockets application
  844.  * to extract the error code from the lParam in the response
  845.  * to a WSAAsyncSelect().
  846.  *)
  847. function WSAGetSelectError(lparam: longint): word;
  848.  
  849. implementation
  850.  
  851. uses
  852.   WinProcs;
  853.  
  854. function accept; external 'WINSOCK' index 1;
  855. function bind; external 'WINSOCK' index 2;
  856. function closesocket; external 'WINSOCK' index 3;
  857. function connect; external 'WINSOCK' index 4;
  858. function getpeername; external 'WINSOCK' index 5;
  859. function getsockname; external 'WINSOCK' index 6;
  860. function getsockopt; external 'WINSOCK' index 7;
  861. function htonl; external 'WINSOCK' index 8;
  862. function htons; external 'WINSOCK' index 9;
  863. function inet_addr; external 'WINSOCK' index 10;
  864. function inet_ntoa; external 'WINSOCK' index 11;
  865. function ioctlsocket; external 'WINSOCK' index 12;
  866. function listen; external 'WINSOCK' index 13;
  867. function ntohl; external 'WINSOCK' index 14;
  868. function ntohs; external 'WINSOCK' index 15;
  869. function recv; external 'WINSOCK' index 16;
  870. function recvfrom; external 'WINSOCK' index 17;
  871. function select; external 'WINSOCK' index 18;
  872. function send; external 'WINSOCK' index 19;
  873. function sendto; external 'WINSOCK' index 20;
  874. function setsockopt; external 'WINSOCK' index 21;
  875. function shutdown; external 'WINSOCK' index 22;
  876. function socket; external 'WINSOCK' index 23;
  877.  
  878. function gethostbyaddr; external 'WINSOCK' index 51;
  879. function gethostbyname; external 'WINSOCK' index 52;
  880. function getprotobyname; external 'WINSOCK' index 53;
  881. function getprotobynumber; external 'WINSOCK' index 54;
  882. function getservbyname; external 'WINSOCK' index 55;
  883. function getservbyport; external 'WINSOCK' index 56;
  884. function gethostname; external 'WINSOCK' index 57;
  885.  
  886. function WSAAsyncSelect; external 'WINSOCK' index 101;
  887. function WSAAsyncGetHostByAddr; external 'WINSOCK' index 102;
  888. function WSAAsyncGetHostByName; external 'WINSOCK' index 103;
  889. function WSAAsyncGetProtoByNumber; external 'WINSOCK' index 104;
  890. function WSAAsyncGetProtoByName; external 'WINSOCK' index 105;
  891. function WSAAsyncGetServByPort; external 'WINSOCK' index 106;
  892. function WSAAsyncGetServByName; external 'WINSOCK' index 107;
  893. function WSACancelAsyncRequest; external 'WINSOCK' index 108;
  894. function WSASetBlockingHook; external 'WINSOCK' index 109;
  895. function WSAUnhookBlockingHook; external 'WINSOCK' index 110;
  896. function WSAGetLastError; external 'WINSOCK' index 111;
  897. procedure WSASetLastError; external 'WINSOCK' index 112;
  898. function WSACancelBlockingCall; external 'WINSOCK' index 113;
  899. function WSAIsBlocking; external 'WINSOCK' index 114;
  900. function WSAStartup; external 'WINSOCK' index 115;
  901. function WSACleanup; external 'WINSOCK' index 116;
  902.  
  903. function __WSAFDIsSet; external 'WINSOCK' index 151;
  904.  
  905. procedure Fd_Clr(fd: TSocket; aset: PFd_Set);
  906. var
  907.   i: u_int;
  908. begin
  909.   for i := 0 to aset^.fd_count do
  910.     begin
  911.     if aset^.fd_array[i] = fd then (* found the one to clear *)
  912.       begin
  913.       while i < (aset^.fd_count-1) do
  914.         begin
  915.         aset^.fd_array[i] := aset^.fd_array[i+1];
  916.         inc(i);
  917.         end;
  918.       dec(aset^.fd_count);
  919.       break;
  920.       end;
  921.     end;
  922. end;
  923.  
  924. procedure Fd_Set(fd: TSocket; aset: PFd_Set);
  925. begin
  926.   if aset^.fd_count < FD_SETSIZE then
  927.     begin
  928.     aset^.fd_array[aset^.fd_count] := fd;
  929.     inc(aset^.fd_count);
  930.     end;
  931. end;
  932.  
  933. procedure Fd_Zero(aset: PFd_Set);
  934. begin
  935.   aset^.fd_count := 0;
  936. end;
  937.  
  938. function Fd_IsSet(fd: TSocket; aset: PFd_Set): boolean;
  939. begin
  940.   Fd_IsSet := (__WSAFDIsSet(fd, aSet) > 0);
  941. end;
  942.  
  943. function h_addr(aHostEnt: THostEnt): PChar;  (* RMB 09/29/94 1.02 *)
  944. begin
  945.   h_addr := aHostEnt.h_addr_list^;
  946. end;
  947.  
  948. function s_addr(S_un: TIn_Addr): u_long;
  949. begin
  950.   s_addr := S_un.S_addr;  (* can be used for most tcp & ip code *)
  951. end;
  952.  
  953. function s_host(S_un: TIn_Addr): u_char;
  954. begin
  955.   s_host := S_un.S_un_b.s_b2;  (* host on imp *)
  956. end;
  957.  
  958. function s_net(S_un: TIn_Addr): u_char;
  959. begin
  960.   s_net := S_un.S_un_b.s_b1;  (* network *)
  961. end;
  962.  
  963. function s_imp(S_un: TIn_Addr): u_short;
  964. begin
  965.   s_imp := S_un.S_un_w.s_w2; (* imp *)
  966. end;
  967.  
  968. function s_impno(S_un: TIn_Addr): u_char;
  969. begin
  970.   s_impno := S_un.S_un_b.s_b4; (* imp $ *)
  971. end;
  972.  
  973. function s_lh(S_un: TIn_Addr): u_char;
  974. begin
  975.   s_lh := S_un.S_un_b.s_b3;  (* logical host *)
  976. end;
  977.  
  978. function In_ClassA(i : longint) : boolean;
  979. begin
  980.   In_ClassA := ((i and $80000000) = 0);
  981. end;
  982.  
  983. function In_ClassB(i : longint) : boolean;
  984. begin
  985.   In_ClassB := ((i and  $c0000000) = $80000000);
  986. end;
  987.  
  988. function In_ClassC(i : longint) : boolean;
  989. begin
  990.   In_ClassC := ((i and $e0000000) = $c0000000);   (* RMB 03/10/96 1.03 *)
  991.                                                   (* 05/15/93 to original WINSOCK.H *)
  992. end;
  993.  
  994. function h_errno : integer;
  995. begin
  996.   h_errno := WSAGetLastError;
  997. end;
  998.  
  999. function WSAMakeAsyncReply(buflen, error: word): longint;
  1000. begin
  1001.   WSAMakeAsyncReply := MakeLong(buflen, error);
  1002. end;
  1003.  
  1004. function WSAMakeSelectReply(event, error: word): longint;
  1005. begin
  1006.   WSAMakeSelectReply := MakeLong(event, error);
  1007. end;
  1008.  
  1009. function WSAGetAsyncBuflen(lparam: longint): word;
  1010. begin
  1011.   WSAGetAsyncBuflen := LoWord(lparam);
  1012. end;
  1013.  
  1014. function WSAGetAsyncError(lparam: longint): word;
  1015. begin
  1016.   WSAGetAsyncError := HiWord(lparam);
  1017. end;
  1018.  
  1019. function WSAGetSelectEvent(lparam: longint): word;
  1020. begin
  1021.   WSAGetSelectEvent := LoWord(lparam);
  1022. end;
  1023.  
  1024. function WSAGetSelectError(lparam: longint): word;
  1025. begin
  1026.   WSAGetSelectError := HiWord(lparam);
  1027. end;
  1028.  
  1029. END.
  1030.